#pragma once

#include <iostream>
#include <functional>
#include <unistd.h>
#include <string>
#include <memory>
#include <cstring>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include<fcntl.h>
#include "Log.hpp"

using namespace LogModule;

void Usage(std::string proc)
{
    std::cerr<<"Usage: "<< proc << " port"<<std::endl;
}

enum ExitCode
{
    OK = 0,
    USAGE_ERR,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR,
    FORK_ERR,
    OPEN_ERR,
    EPOLL_CREATE_ERROR,
    EPOLL_CTL_ERROR
};

class NoCopy
{
public:
    NoCopy(){}
    ~NoCopy(){}
    NoCopy(const NoCopy&) = delete;
    const NoCopy &operator= (const NoCopy&) = delete;
};
void SetNonBlock(int fd)
{
    int fl = fcntl(fd,F_GETFL);
    if(fl < 0)
    {
        return;
    }
    fcntl(fd,F_SETFL,fl | O_NONBLOCK);
}


#define CONV(addr) ((struct sockaddr*)&addr)